package com.qf.java2207.no3_teamproject_springboot_01.controller;
//须知少时凌云志，曾许人间第一流


import com.qf.java2207.no3_teamproject_springboot_01.common.R;
import com.qf.java2207.no3_teamproject_springboot_01.pojo.SecurityEquipment;
import com.qf.java2207.no3_teamproject_springboot_01.service.SecurityEquipmentService;
import com.qf.java2207.no3_teamproject_springboot_01.vo.LayuiPageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/equipment")
public class SecurityEquipmentController {

    @Autowired
    private SecurityEquipmentService securityEquipmentService;



    @RequestMapping("/equipmentList")
    //public LayuiPageVo<SecurityEquipment> securityEquipmentPageData(Integer page,Integer limit){
    // 注意 这里的  @RequestParam 不能省略   省略的话就不能获取参数了
    public LayuiPageVo<SecurityEquipment> securityEquipmentPageData(@RequestParam Map<String,Object> params){
        System.out.println(params);
        //return securityEquipmentService.securityEquipmentPageData(page,limit);
        return securityEquipmentService.securityEquipmentPageData(params);
    }



    // 这个请求  会匹配到 预检请求
    @GetMapping("/deleteSecurityEquipment")
    public R deleteSecurityEquipment(Integer id){
        //根据Id删除学生信息
        int result = securityEquipmentService.deleteSecurityEquipment(id);
        if(result==1){
            return R.ok();
        }else{
            return R.error();
        }
    }

    @RequestMapping("/updateSecurityEquipment")
    public R updateSecurityEquipment(SecurityEquipment securityEquipment){
        System.out.println(securityEquipment);

        int result = securityEquipmentService.updateSecurityEquipment(securityEquipment);
        if(result==1){
            return R.ok();
        }else{
            return R.error();
        }

    }


    @RequestMapping("/addSecurityEquipment")
    public R addSecurityEquipment(SecurityEquipment securityEquipment){
        System.out.println(securityEquipment);

        int result = securityEquipmentService.addSecurityEquipment(securityEquipment);
        if(result==1){
            return R.ok();
        }else{
            return R.error();
        }

    }


}
